import dayjs from 'dayjs';
import mongoose, { Schema } from 'mongoose';

export interface IAccess {
	_id: string;
	path: string;
	method: string;
	ip: string;
	agent: string;
	date: string;
}

const AccessSchema = new Schema<IAccess>(
	{
		method: { type: String, required: true },
		path: { type: String, required: true },
		ip: { type: String, required: true },
		agent: { type: String, required: true },
		date: {
			type: String,
			default: () => dayjs().format('YYYY年MM月DD日 HH:mm:ss'),
		},
	},
	{
		collection: 'access',
	}
);

export const AccessModel = mongoose.model<IAccess>('Access', AccessSchema);
